﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDB.LinqModel.Data;
using CDB.LinqData;
using CDB.LinqModel;

public partial class viewProperties : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    Property property;
    List<Property> properties = new List<Property>();
    User user;
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] == null)
            Response.Redirect("default.aspx");
        else
            FillProperties(Session["User"].ToString());
    }
    private void FillProperties(string userName)
    {
        User nUser = new User(_dataObject);
        nUser.UserName = userName;
        nUser.GetUserByUserName();

        if (nUser.Id != 0)
        {
            property = new Property(_dataObject);
            properties = property.GetAllPropertiesByUserId(nUser.Id);

            if (properties.Count > 0)
            {
                tdMessage.InnerHtml = string.Empty;
                grdProperties.DataSource = properties;
                grdProperties.DataBind();
            }
            else
            {
                tdMessage.InnerHtml = "No Properties added.";
                grdProperties.DataSource = null;
                grdProperties.DataBind();
            }
        }
    }
}